<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>校园招聘管理系统</title>
		<link type="text/css" rel="stylesheet" href="css/backend.css" />
	</head>
	<!-- RecruitInfo的id从+20开始 -->
	<body onload="loadform(1)">
		<div class="container">
			<div class="wrapper">
				<div class="header">
					学生端
				</div>
				<!-- log图片 -->
				<div class="log"><img src="img/logoStu.jpg" style="width: 100%;"></div>
				<!-- 侧边栏 -->
				<div class="aside">
					<ul>
						<li>
							<a href="#" onclick="loadform(1)">首页</a>
						</li>

						<li>
							<a href="#" onclick="addNotes()">个人简历 </a>
							<!-- <ul>
								<li><a href="#">子导航1</a></li>
								<li><a href="#">子导航2</a></li>
								<li><a href="#">子导航3</a></li>
							</ul> -->
						</li>

						<li>
							<a href="#" onclick="selectRecruitInfo()">查看招聘信息</a>
						</li>


						<li>
							<a href="#" onclick="selectPushInfo()">查看投递信息</a>
						</li>

						<li>
							<a href="#" onclick="remindYaoQing()">企业邀请通知</a>
						</li>
					</ul>
				</div>

				<!-- 主体部分 -->
				<div class="section">
					<div id="1" class="module">
						<img src="img/首页2.jpg" style="width: 60%; margin-left: 250px;margin-top: 100px;">

						<!-- 个人简历 :根据主键account(set,get),如果填写过就update方法,没填写过就save方法-->
					</div>
					<div id="2" class="module">


						<table border="1" width="100%">
							<tr>
								<th style="background-color: lightcyan;">姓名</th>
								<th style="background-color: lightcyan;">年龄</th>
								<th style="background-color: lightcyan;">性别</th>
								<th style="background-color: lightcyan;">所学专业</th>
								<th style="background-color: lightcyan;">联系电话</th>
								<th style="background-color: lightcyan;">qq邮箱</th>
							</tr>

							<form>
								<tr>

									<th>
										<input id="6" type="text" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="7" type="number" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="8" type="text" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="9" type="text" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="10" type="text" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="11" type="email" style="height: 40px;width: 100%" />
									</th>

								</tr>

								<tr>
									<th colspan="3" style="background-color: lightcyan;">个人简介</th>
									<th colspan="3" style="background-color: lightcyan;">获奖情况</th>
								</tr>
								<tr>
									<th colspan="3">
										<textarea id="12" rows="4" cols="90" style="width: 100%;"></textarea>
									</th>
									<th colspan="3">
										<textarea id="13" rows="4" cols="90" style="width: 100%;"></textarea>
									</th>
								</tr>
						</table>
						<div class="box1">
							<input class="btn" type="button" value="保存" style="float: left;margin-top: 10%;margin-left: 20%;" onclick="saveInfo()">
							<input class="btn" type="reset" value="重置" style="float: left;margin-left: 40%; margin-top:10% ;">
						</div>
						</form>
					</div>


					<!-- 查看企业招聘信息 投递简历 -->
					<div id="3" class="module">
						<div id="14" class="recruitInfoBox">
							<!-- <input type="button" onclick="createNewElements()" value="32322" /> -->
						</div>
					</div>





					<!-- 查看投递信息:查找表company_student,如果stu账号匹配就返回company账号,根据company账号返回招聘信息,已投递的,根据true和false判断是否要面试 -->
					<div id="4" class="module">
						<div id="15" class="recruitInfoBox" style="height: 150px;">
							<p style="font-style: italic;font-weight: bold;color: #0000FF;font-size: 50px;">点击下一条查看已投递的招聘信息</p>
						</div>
						<input type="button" onclick="aa()" value="下一条" class="btn" style="position: relative;left: 500px;" />
					</div>

					<!-- 企业邀请通知 -->
					<div id="16" class="module">
						<div id="17" class="recruitInfoBox">
							企业邀请通知
						</div>
					</div>
				</div>

			</div>
		</div>
	</body>
	<script src="./js/axios-0.18.0.js"></script>
	<script src="js/login.js"></script>
	<script language="JavaScript">
		var companyAccount = new Array;
		var accountHaveValue = "false"; //判断简历是否已经写过信息,决定是update还是save
		//请求url
		var account = sessionStorage.getItem("user");
		var locaUrl;
		setTimeout("getLocation()");
		function getLocation(){
			// 获取当前页面的完整 URL
			var currentUrl = window.location.href;
			// 提取网段部分
			var hostname = (new URL(currentUrl)).hostname;
			// 构建 Ajax 请求的 URL
			locaUrl = "http://" + hostname; //+ ":8080/recruitInfo";

			// alert(document.cookie.toString());
			// alert(sessionStorage.getItem("user"));
		}

		//打开文件时加载首页
		function loadform(id) {
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById(id).classList.add("active");
		}

		//切换个人简历页面+loadNoteData(temp1)
		function addNotes() {
			var temp;
			var a = 0;
			
			loadNoteData();
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("2").classList.add("active");
		}
		//加载个人简历信息+addNotes
		function loadNoteData() {
			// var account1 = '<%= session.getAttribute("user") %>';
			var account1 = sessionStorage.getItem("user")

			var xmlHttpRequest = new XMLHttpRequest();
			axios.withCredentials = true;
			axios.get(locaUrl+':8080/student/' + account1).then(result => {
				accountHaveValue = "true"; //已经写过简历,之后用修改不用save,因为主键

				document.getElementById("6").value = result.data.data.name;
				document.getElementById("7").value = result.data.data.age;
				document.getElementById("8").value = result.data.data.sex;
				document.getElementById("9").value = result.data.data.major;
				document.getElementById("10").value = result.data.data.phone;
				document.getElementById("11").value = result.data.data.email;
				document.getElementById("12").value = result.data.data.introduction;
				document.getElementById("13").value = result.data.data.reward;
			});
		}

		//保存个人简历信息
		function saveInfo() {
			if (account == "" || account == null) {
				alert("系统错误，请重新登陆");
				location = '/webapp/login.html';
				return;
			}
			var account1 = account;
			var name1 = document.getElementById("6").value;
			var age1 = document.getElementById("7").value;
			var sex1 = document.getElementById("8").value;
			var major1 = document.getElementById("9").value;
			var phone1 = document.getElementById("10").value;
			var email1 = document.getElementById("11").value;
			var introduction1 = document.getElementById("12").value;
			var reward1 = document.getElementById("13").value;
			const data = {
				account: account1,
				age: age1,
				sex: sex1,
				major: major1,
				phone: phone1,
				email: email1,
				introduction: introduction1,
				reward: reward1,
				name: name1
			};
			if (name1 == "" || age1 == "" || sex1 == "" || major1 == "" || phone1 == "" || email1 == "" || introduction1 == "" ||
				reward1 == "") {
				alert("请不要有空值");
				return;
			} else if (account != "" && accountHaveValue == "false") { //简历信息未填写过用save
				//保存insert
				axios.withCredentials = true;
				axios.post(locaUrl+':8080/student',data).then(result => {

					if (result.data.code == "1") {
						alert("保存成功");
					}else if(result.data.code == "0") {
						// alert(result.data.msg);
						alert("保存失败");
					}
				});
			} else if (accountHaveValue == "true") {
				//update
				// 创建XMLHttpRequest对象
				axios.withCredentials = true;
				axios.put(locaUrl+':8080/student',data).then(result => {

					if (result.data.code == "1") {
						alert("修改成功");
					}else if(result.data.code == "0") {
						// alert(result.data.msg);
						alert("修改失败");
					}
				});
			}
		}


		//切换查看招聘信息页面,为true才显示
		function selectRecruitInfo() {

			var userList = document.getElementById('14');
			userList.innerHTML = "";
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("3").classList.add("active");
			//加载招聘信息
			axios.withCredentials = true;
			axios.get(locaUrl+':8080/recruitInfo').then(result => {
				var recruitInfoBox = document.getElementById("14");
				//遍历数据输出到网页
				for (var i = 0; i <= result.data.data.length; i++) {
					if (result.data.data[i].post == "true") { //是否被管理员同意投放
						// var recruitInfo = document.createElement("p");
						var text = document.createTextNode("招聘职位:" + result.data.data[i].title);
						recruitInfoBox.appendChild(text); //将标题添加到页面

						var text = document.createTextNode("   " + "工资:" + result.data.data[i].salary);
						recruitInfoBox.appendChild(text); //将标题添加到页面

						var text = document.createTextNode("   " + "入职需求" + result.data.data[i].need);
						recruitInfoBox.appendChild(text); //将标题添加到页面

						var text = document.createTextNode("   " + "公司地址:" + result.data.data[i].address);
						recruitInfoBox.appendChild(text); //将标题添加到页面

						var button1 = document.createElement("input");
						button1.type = "button";
						button1.value = "投递";
						button1.name = result.data.data[i].account; //将账户传给按钮的name
						button1.setAttribute("onclick", "touDiJianLi(name)"); //事件用这个
						var link2 = document.createElement("br"); //换行一下
						recruitInfoBox.appendChild(link2); //将标题添加到页面
						recruitInfoBox.appendChild(button1);

						var link2 = document.createElement("hr"); //分隔一下
						recruitInfoBox.appendChild(link2);
					}
				}
			})
		}

		// 投递简历 company_student表投递简历
		function touDiJianLi(name) {
			alert(name);
			var ac = name;
			var acs = account;
			if (account == "" || account == null) {
				alert("系统错误，请重新登陆");
				location = '/webapp/login.html';
				return;
			}
			//发送数据给company_student表
			const data = {
				accountCm: ac,
				accountStu: account,
				whether: "false"
			};
			axios.withCredentials = true;
			axios.post(locaUrl+':8080/toudi',data).then(result => {

				if (result.data.code == "1") {
					alert("投递成功");
				}else if(result.data.code == "0") {
					alert(result.data.msg);
				}
			});
		}
		var accountCompany = new Array;
		//切换查看已投递信息页面
		function selectPushInfo() {
			var a = new Array;
			if (account == "" || account == "null") {
				alert("系统错误,请重新登录");
			}
			var accountStu = account;
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("4").classList.add("active");
			axios.withCredentials = true;
			axios.get(locaUrl+':8080/stu/' + accountStu).then(result => {
				accountCompany = result.data.data;
				console.log(result.data);
			})
		}

		var t = 0;
		var t2 = 0;
		var t3 = 0;

		function aa() {
			var userList = document.getElementById('15');
			userList.innerHTML = "";
			alert("第" + (t + 1) + "条");

			var temp = t;

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/recruitInfo/' + accountCompany[t].accountCm).then(result => {
				var recruitInfoBox = document.getElementById("15");
				console.log(result);
				var text = document.createTextNode("招聘职位:" + result.data.data[0].title);
				recruitInfoBox.appendChild(text); //将标题添加到页面
				console.log(t);


				var text = document.createTextNode(",工资:" + result.data.data[0].salary);
				recruitInfoBox.appendChild(text); //将标题添加到页面


				var text = document.createTextNode("   ,  " + "入职需求:" + result.data.data[0].need);
				recruitInfoBox.appendChild(text); //将标题添加到页面



				var text = document.createTextNode("  ,   " + "公司地址:" + result.data.data[0].address);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				if (accountCompany[temp].whether == "true") {
					var text = document.createTextNode(",招聘状态:面试官收取，可以去面试");
					recruitInfoBox.appendChild(text); //将标题添加到页面

				} else if (accountCompany[temp].whether == "false") {
					var text = document.createTextNode(",招聘状态:投递中...");
					recruitInfoBox.appendChild(text); //将标题添加到页面
				}

			})
			if (accountCompany.length - 1 == t) {
				t = -1;
			}
			t++;


		}

		//根据学生账号查yaoqing表, 返回公司账号   二 根据返回的公司账号去查 recruit_info表,将这个信息返回过来
		var accountCm = new Array; //yaoqing表里的数据
		function remindYaoQing() {
			var accountStu = account;
			var a = new Array;
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("16").classList.add("active");

			var recruitInfoBox = document.getElementById("17");
			recruitInfoBox.innerHTML = ""
			// recruitInfoBox.innerHTML = "";
			if (account == "" || account == "null") {
				alert("系统错误,请重新登录");
				location = '/webapp/login.html';
				return;
			}


			axios.withCredentials = true;
			axios.get(locaUrl+':8080/selectYaoQing/' + accountStu).then(result => {
				accountCm=result.data.data;
				getYaoQingCmInfo();
			})

		}
		var count = 0;
		function getYaoQingCmInfo(){
			var recruitInfoBox = document.getElementById("17");
			var a = accountCm.length;
			account1 = accountCm[count].accountCm;
			axios.withCredentials = true;
			axios.get(locaUrl+':8080/recruitInfo/' + account1).then(result => {
				var text = document.createTextNode("招聘职位:" + result.data.data[0].title);
				recruitInfoBox.appendChild(text); //将标题添加到页
				var text = document.createTextNode("   " + "工资:" + result.data.data[0].salary);
				recruitInfoBox.appendChild(text); //将标题添加到页面
				var text = document.createTextNode("   " + "入职需求" + result.data.data[0].need);
				recruitInfoBox.appendChild(text); //将标题添加到页面



				var text = document.createTextNode("   " + "公司地址:" + result.data.data[0].address);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var button1 = document.createElement("input");
				button1.type = "button";
				button1.value = "同意邀请";
				button1.name = result.data.data[0].account; //将公司账户传给按钮的name
				button1.setAttribute("onclick", "touDiJianLi(name)"); //事件用这个
				var link2 = document.createElement("br"); //换行一下
				recruitInfoBox.appendChild(link2); //将标题添加到页面
				recruitInfoBox.appendChild(button1);

				var link2 = document.createElement("hr"); //分隔一下
				recruitInfoBox.appendChild(link2);
			})
			count++;
			if (count == accountCm.length) {
				count = 0;
				return; //到头就退出
			}
			setTimeout("getTouDiStudentInfo()", 1000);
		}
	</script>


</html>
